#include<bits/stdc++.h>
using namespace std;
int t,n,a[100010],b[100010][20],ans;
int main()
{
    freopen("color.in","r",stdin);
    freopen("color.out","w",stdout);
    cin>>t;
    while(t--)
    {
        ans=0;
        cin>>n;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
        }
        for(int i=pow(2,n)-1;i>=0;i--)
        {
            int cnt=0,sum=0,i2=i;
            while(i2!=0)
            {
                b[i][++cnt]=i2%2;
                i2/=2;
            }
            for(int j=cnt+1;j<=n;j++)
            {
                b[i][j]=0;
            }
            for(int k=1;k<=n;k++)
            {
                for(int j=k-1;j>1;j--)
                {
                    while(b[i][j]!=b[i][k]&&j>=1)
                    {
                        j--;
                    }
                    if(a[j]==a[k])
                    {
                        sum+=a[j];
                    }
                    break;
                }
            }
            ans=max(ans,sum);
        }
        cout<<ans<<endl;
    }
    return 0;
}

